import http from '@/utils/request'

// 搜索商品,值为undefined，axios不会发送
// sortType:all-按综合搜索(默认)，sales-按销量搜索，price-按价格搜索,
// sortPrice:0-价格从低到高， 1-价格从高到低
// categoryId 类型搜索
// goodsName: 商品, page：页数
export const searchGoodsList = (sortType = 'all', sortPrice, categoryId, goodsName, page) => {
  const params = {
    sortType,
    sortPrice,
    categoryId,
    goodsName,
    page
  }
  return http.get('/goods/list', { params })
}

// 获取商品详情
export const getGoodsDetail = (goodsId) => {
  return http.get('/goods/detail', { params: { goodsId } })
}

// 获取商品评价
export const getComments = (goodsId) => {
  const params = {
    goodsId,
    limit: 3 // 获取几条评论
  }
  return http.get('/comment/listRows', { params })
}

// 获取商品评价总数
export const getCommentsTotal = (goodsId) => {
  return http.get('/comment/total', { params: { goodsId } })
}
